package com.wc.算法提高课.D第四章_高级数据结构.线段树.一个简单的整数问题2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/17 22:06
 * @description https://www.acwing.com/problem/content/244/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] w = new int[N];
    // sum = tr[u][0], lazy = tr[u][1]
    static long[][] tr = new long[N << 2][2];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) w[i] = sc.nextInt();
        build(1, 1, n);
        while (m-- > 0) {
            String op = sc.next();
            int x = sc.nextInt(), y = sc.nextInt();
            if (op.equals("Q")) {
                out.println(query(1, 1, n, x, y));
            } else {
                int d = sc.nextInt();
                modify(1, 1, n, x, y, d);
            }
        }
        out.flush();
    }

    static void build(int u, int l, int r) {
        if (l == r) {
            tr[u][0] = w[l];
            return;
        }
        int mid = l + r >> 1;
        build(u << 1, l, mid);
        build(u << 1 | 1, mid + 1, r);
        pushUp(u);
    }

    static void pushUp(int u) {
        tr[u][0] = tr[u << 1][0] + tr[u << 1 | 1][0];
    }

    static void pushDown(int u, int l, int r) {
        int mid = l + r >> 1;
        long lazy = tr[u][1];
        tr[u << 1][0] += lazy * (mid - l + 1);
        tr[u << 1 | 1][0] += lazy * (r - (mid + 1) + 1);
        tr[u << 1][1] += lazy;
        tr[u << 1 | 1][1] += lazy;
        tr[u][1] = 0;
    }

    static void modify(int u, int l, int r, int ql, int qr, long d) {
        if (l == ql && r == qr) {
            tr[u][0] += d * (r - l + 1);
            tr[u][1] += d;
            return;
        }
        pushDown(u, l, r);
        int mid = l + r >> 1;
        if (qr <= mid) modify(u << 1, l, mid, ql, qr, d);
        else if (ql > mid) modify(u << 1 | 1, mid + 1, r, ql, qr, d);
        else {
            modify(u << 1, l, mid, ql, mid, d);
            modify(u << 1 | 1, mid + 1, r, mid + 1, qr, d);
        }
        pushUp(u);
    }

    static long query(int u, int l, int r, int ql, int qr) {
        if (l == ql && r == qr) {
            return tr[u][0];
        }
        pushDown(u, l, r);
        int mid = l + r >> 1;
        if (qr <= mid) return query(u << 1, l, mid, ql, qr);
        if (ql > mid) return query(u << 1 | 1, mid + 1, r, ql, qr);
        return query(u << 1, l, mid, ql, mid) + query(u << 1 | 1, mid + 1, r, mid + 1, qr);
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
